﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Shove.Web.UI;

public partial class UserControls_ArticleList : UCBase
{
    public UserControls_ArticleList()
    {
        Name = "文章列表";

        swpas = new ShoveWebPartAttribute[13];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 759, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航单元格高度", "1,500", 23, "导航单元格高度");
        swpas[2] = new ShoveWebPartAttribute_Int("导航单元格宽度", "1,600", 139, "导航单元格宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("标题行高", "1,200", 23, "标题行高");
        swpas[4] = new ShoveWebPartAttribute_Int("标题单元格百分比", "1,100", 98, "标题单元格百分比");

        swpas[5] = new ShoveWebPartAttribute_Color("控件边框颜色", "#E7C890", "控件边框颜色");
        swpas[6] = new ShoveWebPartAttribute_Color("分割线颜色", "#cccccc", "分割线颜色");

        swpas[7] = new ShoveWebPartAttribute_Image("导航背景图片1", "", "images/bg_gold_23.jpg", "导航背景图片1");
        swpas[8] = new ShoveWebPartAttribute_Image("导航背景图片2", "", "images/bg_gold_23_2.jpg", "导航背景图片2");
        swpas[9] = new ShoveWebPartAttribute_Image("标题前图片", "", "images/point_yuan.jpg", "标题前图片");

        swpas[10] = new ShoveWebPartAttribute_Text("导航字体样式", "", "black12", "导航字体样式");
        swpas[11] = new ShoveWebPartAttribute_Text("标题CSS样式", "", "black12", "标题CSS样式");

        swpas[12] = new ShoveWebPartAttribute_Int("每页几条数据", "1,50", 4, "每页几条数据");
    }

    private void Initlayout()
    {
        tabctr.Width = swpAttributes[0];
        tabctr.BgColor = swpAttributes[5];

        tdsign.Width = swpAttributes[2];
        tdsign.Height = swpAttributes[1];
        tdsign.Style.Add("background-image", "url('" + swpAttributes[7] + "')");
        tdsign.Attributes.Add("class", swpAttributes[10]);

        tdspace.Style.Add("background-image", "url('" + swpAttributes[8] + "')");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["CurrentPage"] = null;
        }

        Initlayout();

        LoadData();
    }

    /// <summary>
    /// 根据所点击的(帮助中心，购物指南，商店公告，常见问题)加载文章列表
    /// </summary>
    private void LoadData()
    {
        string Type  =  Shove._Web.Utility.GetRequest("Type");

        lbType.Text = Type;
        long ShopID = _Site.ID;
        long ArticleTypeID = 0;

        DataTable dt = new DAL.Tables.tbl_Site_ArticleType().Open("ID", "TypeName='" + Type + "'", "");
        if (dt != null && dt.Rows.Count > 0)
        {
            ArticleTypeID = Shove._Convert.StrToLong(dt.Rows[0]["ID"].ToString(), 0);
        }

        this.Page1.FindType = 0;
        this.Page1.Field1 = "";
        this.Page1.Field2 = "";
        this.Page1.Like1 = "";
        this.Page1.Like2 = "";
        Page1.DataListID = dlArticleList;

        Page1.TableName = "V_Shop_Article";
        Page1.Condition = "Where ShopID=" + ShopID + "  and ArticleTypeID=" + ArticleTypeID + "";
        Page1.PageSize = Shove._Convert.StrToInt(swpAttributes[12], 4);
    }

    protected void dlArticleList_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.EditItem||e.Item.ItemType == ListItemType.Item||e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HtmlImage imgpoint = (HtmlImage)e.Item.FindControl("imgpoint");
            imgpoint.Src = "~/" + swpAttributes[9];

            HtmlTableCell tdtitle = (HtmlTableCell)e.Item.FindControl("tdtitle");
            tdtitle.Height = swpAttributes[3];
            tdtitle.Width = swpAttributes[4] + "%";
            tdtitle.Attributes.Add("class", swpAttributes[11]);

            HtmlTableCell tdline = (HtmlTableCell)e.Item.FindControl("tdline");
            tdline.BgColor = swpAttributes[6];
        }
    }
}
